package github.leavesczy.reactivehttpsamples.widget.maintab;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.ColorRes;

import github.leavesczy.reactivehttpsamples.R;


public class MainBottomTabItem extends RelativeLayout {
    private ImageView tabImage;
    private TextView tabText;

    public MainBottomTabItem(Context context) {
        super(context);
        initView();
    }

    public MainBottomTabItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public MainBottomTabItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View view = View.inflate(getContext(), R.layout.item_tab, this);
        tabImage = view.findViewById(R.id.iv_tab_img);
        tabText = view.findViewById(R.id.iv_tab_text);

    }


    public void setDrawable(int drawable) {
        tabImage.setImageResource(drawable);
        tabImage.setVisibility(VISIBLE);
        tabText.setVisibility(GONE);
    }

    
    public void setText(String text,@ColorRes int color) {
        tabText.setText(text);
        //tabText.setTextColor(ColorStateList.valueOf());
       // tabText.setTextColor(getResources().getColor(color));
        tabImage.setVisibility(GONE);
        tabText.setVisibility(VISIBLE);
        tabText.setSelected(false);
    }

    @Override
    public void setSelected(boolean selected) {
        super.setSelected(selected);
        tabImage.setSelected(selected);
        tabText.setSelected(selected);
        tabText.setTypeface(selected?Typeface.DEFAULT_BOLD:Typeface.DEFAULT);
    }

}
